package com.njits.traffic.oscache;
import java.util.Date;
import com.opensymphony.oscache.base.NeedsRefreshException;
import com.opensymphony.oscache.general.GeneralCacheAdministrator;

public class BaseCache extends GeneralCacheAdministrator {
	private int refreshPeriod; 
	private String keyPrefix; 
	private static final long serialVersionUID = -4397192926052141162L;

	public BaseCache(String keyPrefix, int refreshPeriod) {
		super();
		this.keyPrefix = keyPrefix;
		this.refreshPeriod = refreshPeriod;
	}

	
	public void put(String key, Object value) {
		this.putInCache(key, value);
	}

	
	public void remove(String key) {
		this.flushEntry(key);
	}

	
	public void removeAll(Date date) {
		this.flushAll(date);
	}

	public void removeAll() {
		this.flushAll();
	}

	
	public Object get(String key) throws Exception {
		try {
			return this.getFromCache(key, this.refreshPeriod);
		} catch (NeedsRefreshException e) {
			this.cancelUpdate(key);
			throw e;
		}
	}
}
